home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
OTHER_LA
/
2014.ZIP
/
TIMEDATE.TXT
< prev
Wrap
Text File
|
1989-04-25
|
6KB
|
181 lines
# ╔═╕ ╔═╗ ╔═╗
╚═╗ ╠═╝ ╠═╣
╘═╝∙╨ ∙ ╜ ╙∙
TIMEDATE 1
Application:
The TIMEDATE segment contains procedures to aquire the time and
date from MS/DOS (tm). These may then be printed and manipulated using
further procedures from the segment which includes a procedure for
recording elapsed times during a program run.
Specifications:
BOOL frac secs := FALSE;
BOOL alpha day := FALSE;
PROC print time now = VOID:
PROC print date now = VOID:
PROC print day name = VOID:
The number of character positions occupied by both "print time
now" and "print date now" at default settings is 8. If fract secs :=
TRUE then "print time now" occupies 11 character positions and includes
hundredths of seconds. If alpha day := TRUE then "print day now"
occupies 18 character positions and includes the name of the day. The
character positions occupied by "print day name" varies between six
(Monday) and eight (Saturday) as required by the actual name.
Example:
In the following example, *LIB directives and new code
introduced by TIMEDATE are offset to the extreme left of the text while
A.A.L. Algol 68 is indented by one or more tab stops. #
*LIB timedate
ps("The time is ");
print time now;
ps(" to the nearest second."); nl;
ps("And the date is ");
print date now; nl;
ps("Or, to an accuracy of 100th second, the time is ");
fract secs := TRUE;
print time now; nl;
fract secs := FALSE; #Optional reset for future usage of print time now.#
ps("If the name of the day is required, the date is ");
alpha day := TRUE;
print date now; nl;
alpha day := FALSE; #Optional resetting of alphabetic day name requirement#
ps("And today is ");
print day name;
#
TIMEDATE 2
Specifications:
MODE TIME = STRUCT(INT hours, minutes, seconds, hundredths);
MODE DATE = STRUCT(INT year, month, day, []CHAR day name);
PROC timenow = TIME:
PROC pelapsed = (TIME t )VOID:
PROC elapsed time = (TIME t )TIME:
t = TIME previously recorded which will be subtracted
from the current time to give an elapsed time.
Example:
To time a computer operation it is necessary to note the time,
perform the operation and then print the time difference. First, a TIME
is declared and initialized to timenow: #
TIME at start = timenow;
#Next a time consuming operation is performed#
INT x := 1;
FOR i TO 10000 DO x +:= 1 OD;
nl;
ps("The time taken for 10000 additions was ");
pelapsed(at start);
nl;
#i.e. the time between "timenow" and "pelapsed" which is printed as the
elapsed time#
ps("Or to the nearest 100th of a second ");
fract secs := TRUE;
pelapsed(at start);
fract secs := FALSE;
nl;
#On some occasions it may be preferable to retain the elapsed time for
printing at a later stage in the program rather than using "pelapsed"
which prints the result immediately it is evaluated.#
TIME another = elapsed time(at start);
#Declares a TIME called "another" which represents the time elapsed
between "at start" and this point in the program. This time, together
with "at start", may be printed at a later stage and this is
demonstrated in the following section.
TIMEDATE 3
Specifications:
PROC ptime = (TIME t )VOID:
PROC datenow = DATE:
PROC pdate = (DATE d )VOID:
t = TIME to be printed.
d = DATE to be printed.
Example:
Continues from that above. These procedures of TIMEDATE enable output
of TIME and DATE entities. This output will be directed to whichever
channel is selected by the A.A.L. Algol 68 "put to ***" procedures.
In order to save a DATE for later printing, perhaps several times, e.g.
at the top of each page of output, it must first be declared and
initialized.#
DATE today = datenow;
#Then the times and date saved above may be printed as follows#
nl; nl;
ps("This program was run on ");
alpha day := TRUE;
pdate(today); nl; #As declared above#
ps("The 10000 additions started at ");
ptime(at start); nl; #Again as declared above#
ps("The time taken for 10000 additions + a few instructions was ");
fract secs := TRUE;
ptime(another); nl; #And yet again as declared above#
#
To validate the examples given in this text, the entire text may be
compiled:-
compile timedate.txt
and the resulting TIMEDATE.COM file may be run with:-
timedate
NOTE:- TIMEDATE.COM contains a worked example utilizing TIMEDATE.A68
and NOT a compiled version of TIMEDATE.A68.
A compiled version of this document is provided in TIMEDATE.COM which
may be run to verify the example. For maximum confidence, please
compile TIMEDATE.TXT for yourself!
Copyright (c) Structured Programming Associates Limited, March 1989.